package com.pulsarwebdevelopment.concordance;

import java.util.HashMap;
import java.util.Map;

import com.pulsarwebdevelopment.concordance.plugins.android.PluginOptionsActivity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class QuizConcordanceActivity extends Activity {
	
	private static final Map<String, String> pluginMap = new HashMap<String, String>(); 
	
	static {
		pluginMap.put("Compiler", "com.pulsarwebdevelopment.concordance.plugins.Compiler");
		pluginMap.put("Live Search", "com.pulsarwebdevelopment.concordance.plugins.android.LiveSearch");
		pluginMap.put("Text Blanker", "com.pulsarwebdevelopment.concordance.plugins.TextBlanker");
		pluginMap.put("List Generator", "");
		pluginMap.put("Unique Highlighter", "");
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
       Spinner pluginSelector = (Spinner) findViewById(R.id.startupPluginSelector);
       ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
    		   									getBaseContext(), android.R.layout.simple_spinner_item);
       for(Map.Entry<String,String> plugin : pluginMap.entrySet()){
    	   adapter.add(plugin.getKey());
       }
       
       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

       pluginSelector.setAdapter(adapter);

    }
    
    /*class StartUpItemSelectedListener implements OnItemSelectedListener{

		public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
			Toast.makeText(parent.getContext(),
					parent.getItemAtPosition(pos).toString(), 
					Toast.LENGTH_SHORT).show();
			
		}

		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			
		}
    	
    }*/
    
    public void startSelectedApp(View button){
    	Spinner pluginSelector = (Spinner) findViewById(R.id.startupPluginSelector);
    	
    	Intent myIntent = new Intent(getApplicationContext(), PluginOptionsActivity.class);
    	myIntent.putExtra("pluginClass", pluginMap.get(pluginSelector.getSelectedItem().toString()));
    	startActivity(myIntent);
    }
}